<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>RequestBody传递JSON类型的参数</title>
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./js/bootstrap.js"></script>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<body>
<button onclick="sendAjax();" class="btn btn-info">发送JSON数据到后端</button>
<script>
    function sendAjax(){
        let user = {id:1,new_name:"王加贝",age:24,birthday:"2022/2/26 9:17:00"};
        let userDate = JSON.stringify(user);
        //使用ajax发送json数据到后端控制器
        $.ajax({
            url:"http://localhost:8080${pageContext.request.contextPath}/ajax/test1",
            type:"post",
            contentType:"application/json",
            data: userDate,  //发送的json参数类型
            success:function (res) {
                console.log(res);
            }

        })
    }
</script>
</body>
</html>
